#!/usr/bin/env bash
#cd /home/china-trader-admin
echo "===============正在从远程服务器拉取代码=================="
result=`git pull`
echo "${result}"
if [ -z "${result}" ]; then
	echo "==================代码更新发生错误!!!!!==============="
	exit 2;
fi
if [[ "${result}" == Alrea* ]]; then
	echo "================代码没有新更新====================="
elif [[ "${result}" == Updating* ]]; then
    cd /home/attract-investment-api
    echo "====================编译项目========================"
	mvn package -Dmaven.test.skip=true
fi

pid=`netstat -nptl |awk '{if($4 ~ /8080$/){print $7}}'|grep -o -E "[0-9]*"`;
echo "pid:  $pid"

if [ -n "$pid" ]; then
	kill -9 $pid
fi
echo "================项目正在启动==================="
cd /home/attract-investment-api/target
nohup nohup java -jar attract.jar &
tail -f nohup.out
